package com.mbigger.synchronize;

/**
 * 类锁的第一种形式，static形式
 *
 * @author mbigg
 *
 */
public class SynchronizedClassClass5 implements Runnable {
    static SynchronizedClassClass5 instance1 = new SynchronizedClassClass5();
    static SynchronizedClassClass5 instance2 = new SynchronizedClassClass5();

    static int i = 0;

    public static void main(String[] args) {
        Thread t1 = new Thread(instance1);
        Thread t2 = new Thread(instance2);
        t1.start();
        t2.start();
        while (t1.isAlive() || t2.isAlive()) {
        }
        System.err.println("finished!");
    }

    public void run() {
        method();
    }

    public void method() {
        synchronized (SynchronizedClassClass5.class) {
            // synchronized(this) {
            System.err.println("我是类锁的第二种形式(*.class)，我叫：" + Thread.currentThread().getName());
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.err.println("运行结束，我叫：" + Thread.currentThread().getName());
        }
    }

}
